﻿using System;
using System.Collections;
using System.Runtime.InteropServices;
using Framework;

namespace Test
{
    [Guid("4457e7c0-b4b7-4226-938c-321891d4a7d0")]
    [NamespaceExtension(Targets.MyComputer, "Extension", FolderAttributes.Folder)]
    public class Extension : NamespaceExtension
    {
        public Extension() : base(new Root())
        {
            
        }
    } ;

    public class Root : DefaultFolderObject
    {
        private readonly IList _items;

        public Root()
        {
            _items = new ArrayList {new Item(0, "One"), new Item(1, "Two"), new Item(2, "Three")};
        }

        #region Overrides of DefaultFolderObject

        public override FolderAttributes Attributes
        {
            get { throw new NotImplementedException(); }
        }

        public override string GetDisplayName(NameOptions opts)
        {
            throw new NotImplementedException();
        }

        public override ShellIcon GetIcon(bool open)
        {
            throw new NotImplementedException();
        }

        public override IEnumerable GetItems(System.Windows.Forms.IWin32Window owner)
        {
            return _items;
        }

        public override byte[] Persist()
        {
            throw new NotImplementedException();
        }

        public override IFolderObject Restore(byte[] data)
        {
            return (IFolderObject)_items[BitConverter.ToInt32(data, 0)];
        }

        #endregion
    } ;

    public class Item : DefaultFolderObject
    {
        private readonly int _n;
        private string _name;

        public Item(int n, string name)
        {
            _n = n;
            _name = name;
        }

        #region Overrides of DefaultFolderObject

        public override FolderAttributes Attributes
        {
            get { return FolderAttributes.CanRename | FolderAttributes.CanCopy; }
        }

        public override string GetDisplayName(NameOptions opts)
        {
            return _name;
        }

        public override byte[] Persist()
        {
            return BitConverter.GetBytes(_n);
        }

        public override IFolderObject Restore(byte[] data)
        {
            throw new NotImplementedException();
        }

        public override void SetName(System.Windows.Forms.IWin32Window owner, string name, NameOptions opts)
        {
            this._name = name;
        }

        #endregion
    } ;
}
